<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:p="http://primefaces.prime.com.tr/ui">

    <body>

        <ui:composition template="./serviceCalculator.xhtml">

            <ui:define name="tabContent">
                <h:form>
                    <p:panel>
                        <table border="0" cellspacing="5">
                            <tbody>
                                <tr>
                                    <td style="vertical-align: top">

                                        <h:panelGrid columns="2">
                                            Độ dài cầu*     
                                            <p:inputText value="#{ketCalculatorBean.doDaiCau}"/>
                                            Tỉnh*    
                                            <p:selectOneMenu id="provinces" value="#{ketCalculatorBean.maTinh}" >
                                                <f:selectItem itemLabel="Miền Bắc - MB" itemValue="MB"/>
                                                <f:selectItems value="#{ketCalculatorBean.provinceMap}"/>
                                            </p:selectOneMenu>
                                            Số ngày thống kê*     
                                            <p:inputText value="#{ketCalculatorBean.soNgayThongKe}"/>
                                        </h:panelGrid>

                                    </td>
                                    <td style="vertical-align: top">
                                        <h:panelGrid columns="2">
                                            Ngày bắt đầu* 
                                            <p:calendar value="#{ketCalculatorBean.startDate}" pattern="dd/MM/yyyy HH:mm:ss" timeZone="Asia/Saigon" navigator="true"
                                                        locale="vi" required="true" requiredMessage="Bạn chưa chọn ngày bắt đầu"/>
                                            Ngày kết thúc* 
                                            <p:calendar id="ketEndDate" value="#{ketCalculatorBean.endDate}" pattern="dd/MM/yyyy HH:mm:ss" timeZone="Asia/Saigon" navigator="true"
                                                        locale="vi" required="true" requiredMessage="Bạn chưa chọn ngày kết thúc">
                                                <p:ajax event="blur" listener="#{ketCalculatorBean.onChangeEndDate()}" update="provinces"/>
                                            </p:calendar>
                                        </h:panelGrid>
                                    </td>
                                </tr>
                            </tbody>
                        </table>

                        <h:panelGrid>
                            <p:commandButton value="Xem kết quả" action="#{ketCalculatorBean.search()}" oncomplete="processingDialog.hide()"
                                             onclick="processingDialog.show()" update="table"/>
                            <p:commandButton value="Tính toán" action="#{ketCalculatorBean.calculate()}" oncomplete="processingDialog.hide()"
                                             onclick="processingDialog.show()" update="table"/>
                        </h:panelGrid>
                    </p:panel>
                </h:form>

                <br/>

                <h:form id="table">
                    <p:dataTable rendered="#{ketCalculatorBean.list.size() > 0}" id="ketResult" value="#{ketCalculatorBean.list}" var="item" 
                                 paginator="#{ketCalculatorBean.list.size() >100}" rows="100" >

                        <f:facet name="header">  
                            Kết quả tính kết cho #{ketCalculatorBean.maTinh} từ 
                            <h:outputText value="#{ketCalculatorBean.startDate}">
                                <f:convertDateTime pattern="dd/MM/yyyy" timeZone="Asia/Saigon"/>
                            </h:outputText>
                            đến 
                            <h:outputText value="#{ketCalculatorBean.endDate}">
                                <f:convertDateTime pattern="dd/MM/yyyy" timeZone="Asia/Saigon"/>
                            </h:outputText>
                        </f:facet> 

                        <p:column headerText="Số cầu" sortBy="#{item.ketResultPK.cauNumber}" filterBy="#{item.ketResultPK.cauNumber}" filterMatchMode="contains">
                            #{item.ketResultPK.cauNumber}
                        </p:column>
                        <p:column headerText="Tỉ lệ trúng cầu" sortBy="#{item.rating}" filterBy="#{item.rating}" filterMatchMode="contains">
                            #{item.rating}
                        </p:column>
                        <p:column headerText="Ngày ăn" sortBy="#{item.winDate}" filterBy="#{item.winDate}">
                            #{item.winDate}
                        </p:column>
                    </p:dataTable>
                </h:form>
            </ui:define>

        </ui:composition>

    </body>
</html>
